# include "tD.h"

const uint32_t tD[] = {
    3178, //t=0
    3139, 3099, 3059, 3017, 2975, 2932, 2888, 2844, 2799, 2754, //t=1~10
    2708, 2662, 2615, 2569, 2521, 2474, 2427, 2379, 2331, 2284, //t=11~20
    2236, 2189, 2141, 2094, 2048, 2001, 1955, 1909, 1864, 1819, //t=21~30
    1775, 1731, 1688, 1645, 1603, 1562, 1522, 1482, 1442, 1404 //t=31~40
};

uint8_t D2t(uint32_t D) {
    if (D > tD[0]) {
        return 0;
    }
    if (D < tD[40]) {
        return 40;
    }

    uint8_t t = 0;

    for (uint8_t i = 0; i < 40; i++) {
        if (D <= tD[i] && D > tD[i + 1]) {
            t = i;
            break;
        }
    }

    return t;
}